package com.yanqu.road.server.cmd.monopolymarket;

import com.yanqu.road.entity.monopolymarket.MonopolyMarket;
import com.yanqu.road.entity.monopolymarket.office.MonopolyMarketOfficeSeatInfo;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.pb.monopolymarket.MonopolyMarketProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.monopolymarket.MonopolyMarketMgr;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

/**
 * @Description
 * @Author cwq
 * @Data 2021/8/12 17:08
 */
@Cmd(code = Protocol.C_CROSS_MONOPOLY_MARKET_SYN_USER_DATA_TO_CROSS, desc = "榷场同步玩家数据")
public class CrossMonopolyMarketSynUserDataCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        MonopolyMarketProto.MonopolyMarketSynUserDataToCrossReqMsg builder = MonopolyMarketProto.MonopolyMarketSynUserDataToCrossReqMsg.parseFrom(packet.getBytes());
        UserBaseInfo userBaseInfo = CrossUserMgr.getUserBaseInfo(packet.getPlayerId());
        if(userBaseInfo != null){
            userBaseInfo.setDecoration(builder.getDecoration());
            userBaseInfo.setTitleId(builder.getTitleId());
            userBaseInfo.setPrestige(builder.getPrestige());
        }
        MonopolyMarket monopolyMarket = MonopolyMarketMgr.getMonopolyMarket(serverId,true);
        if(monopolyMarket != null){
            MonopolyMarketOfficeSeatInfo seatInfo = monopolyMarket.monopolyMarketOffice.seatMap.get(builder.getCurPos());
            if(seatInfo != null && seatInfo.baseInfo.getUserId() == packet.getPlayerId()){
                seatInfo.baseInfo.setDecorationClass((byte)(builder.getDecorationClass()));
                seatInfo.baseInfo.setDecorationOverTime(builder.getDecorationOverTime());
                synchronized (monopolyMarket.monopolyMarketOffice.updateAndAddSeatInfoSet){
                    monopolyMarket.monopolyMarketOffice.updateAndAddSeatInfoSet.add(seatInfo);
                }
            }
        }
    }

    @Override
    public void sendData() {

    }
}
